<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>DOM 事件冒泡</title>
    <style>
      #container {
        width: 400px;
        height: 400px;
        margin: 50px auto;
        border: 1px solid red;
      }
    </style>
  </head>
  <body>
    <div id="container"><button id="btn">按钮</button></div>
    <script>
      const btn = document.getElementById("btn");
      const container = document.getElementById("container");
      btn.onclick = handler;
      container.onclick = handler;
      document.body.onclick = handler;
      function handler(event) {
        event.stopPropagation(); //停止冒泡
        console.log(event.currentTarget); //当前目标, 处理事件的元素
        console.log(event.target); //事件源 只有一个
      }
    </script>
  </body>
</html>
